<?php


namespace app\backend\middleware;
use app\common\RootMiddleware;
use app\backend\model\ReportModel;

/**
 * 审计报告-操作日志
 * Class AfterMiddleware
 * @package app\backend\middleware
 */
class AfterMiddleware extends RootMiddleware
{
    public function handle($request, \Closure $next)
    {
        // 默认流程
        $response = $next($request);
        return $response;
        // 审计报告
        if (empty($response->getData()['code'])) {
            // 获取配置信息
            $reportConfigUri = config('report');
            // 获取请求地址
            $reportUri = [app('http')->getName(), $request->controller(), $request->action()];
            // 入库操作
            if ($request->isAjax() && in_array(join('/', $reportUri), $reportConfigUri)) {
                $insertData = ['admin_id' => adminInfo('id'), 'app' => $reportUri[0], 'controller' => $reportUri[1],
                    'action' => $reportUri[2], 'ip' => $request->ip(), 'params' => json_encode($request->param()),
                    'method' => $request->server('REQUEST_METHOD')];
                ReportModel::create($insertData);
            }
        }
    }
}